
//
//  SinaNewFeatureCell.m
//  oc微博
//
//  Created by 安陆与 on 16/1/19.
//  Copyright © 2016年 安陆与. All rights reserved.
//

#import "SinaNewFeatureCell.h"
#define MAS_SHORTHAND
// 只要添加了这个宏，equalTo就等价于mas_equalTo
#define MAS_SHORTHAND_GLOBALS
// 这个头文件一定要放在上面两个宏的后面
#import "Masonry.h"
@interface  SinaNewFeatureCell()

@property (nonatomic, weak)UIImageView *iconImage;
@property (nonatomic, weak)UIButton *btn;
@end
@implementation SinaNewFeatureCell


- (instancetype)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        [self setupUI];

    }
    
    return self;
}



-(void)setIndex:(int)index{

    _index = index;
    
    NSString *str = [NSString stringWithFormat:@"new_feature_%d",(self.index + 1)];
        
    self.iconImage.image = [UIImage imageNamed:str];
    
    if (_index == 3) {
        self.btn.hidden = NO;
    }else{
        self.btn.hidden = YES;
    }
}

-(void)setupUI{

    //创建imageview
    UIImageView *iconImage = [[UIImageView alloc]init];
    
    self.iconImage = iconImage;
    
    [self addSubview:iconImage];

    //添加约束
   [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
       make.left.equalTo(self.mas_left);
       make.top.equalTo(self.mas_top);
       make.width.equalTo(self.mas_width);
       make.height.equalTo(self.mas_height);
   }];
    
    //添加按钮
    UIButton *btn = [[UIButton alloc]init];
    
    self.btn = btn;
    
    [self addSubview:btn];
    
    //添加约束
    [btn makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconImage.centerX);
        make.bottom.equalTo(self.iconImage.bottom).offset(-100);
    }];
    
    [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:(UIControlStateNormal)];
    [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:(UIControlStateHighlighted)];
    
    [btn setTitle:@"立即进入" forState:(UIControlStateNormal)];
    
    
    [btn addTarget:self action:@selector(enter) forControlEvents:(UIControlEventTouchUpInside)];
    
    [btn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    
    [btn sizeToFit];
}

//点击进入的方法
-(void)enter{

    NSLog(@"点击进入了");
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"change" object:self];
}

@end
